<?php

/**
 *
 *
 *
 * @package lib.model
 * @author r9jason
 */
class ApService
{
    public function constructAp()
    {
        $this->constructApAdmin(1000);
        $this->constructApSetting(2000);
        $this->constructApMemberOrder(3000);
        $this->constructApProduct(4000);
    }

    public function constructApAdmin($seq)
    {
        $lists = array();
        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::MOD_ADMIN);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setMenuLabel("Admin");
        $appUserAccess->setMenuUrl("");
        $appUserAccess->setTreeLevel(1);
        $appUserAccess->setTreeStructure(AP::MOD_ADMIN);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_USER_LIST);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_ADMIN);
        $appUserAccess->setMenuLabel("User List");
        $appUserAccess->setMenuUrl("admin/userList");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_ADMIN ."|". AP::AL_USER_LIST);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_USER_ROLE);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_ADMIN);
        $appUserAccess->setMenuLabel("User Role");
        $appUserAccess->setMenuUrl("admin/userRole");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_ADMIN ."|". AP::AL_USER_ROLE);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_CHANGE_PASSWORD);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_ADMIN);
        $appUserAccess->setMenuLabel("Change Password");
        $appUserAccess->setMenuUrl("admin/changePassword");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_ADMIN ."|". AP::AL_CHANGE_PASSWORD);
        $lists[] = $appUserAccess;

        $count = 0;
        foreach ($lists as $appUserAccess) {
            $appUserAccess->setStatusCode(active);
            $appUserAccess->setTreeSeq($seq + (10 * $count));
            $appUserAccess->save();
            $count++;
        }
    }

    public function constructApSetting($seq)
    {
        $lists = array();

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::MOD_SETTING);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setMenuLabel("Setting");
        $appUserAccess->setMenuUrl("");
        $appUserAccess->setTreeLevel(1);
        $appUserAccess->setTreeStructure(AP::MOD_SETTING);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_CATEGORIES);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_SETTING);
        $appUserAccess->setMenuLabel("Categories");
        $appUserAccess->setMenuUrl("setting/categoriesList");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_SETTING ."|". AP::AL_CATEGORIES);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_FAQ);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_SETTING);
        $appUserAccess->setMenuLabel("Faq");
        $appUserAccess->setMenuUrl("setting/faqList");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_SETTING ."|". AP::AL_FAQ);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_MENU);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_SETTING);
        $appUserAccess->setMenuLabel("Menu");
        $appUserAccess->setMenuUrl("setting/menuList");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_SETTING ."|". AP::AL_MENU);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_DELIVERY_GROUP);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_SETTING);
        $appUserAccess->setMenuLabel("Delivery Group");
        $appUserAccess->setMenuUrl("setting/deliveryGroup");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_SETTING ."|". AP::AL_DELIVERY_GROUP);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_ROUNDABOUT);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_SETTING);
        $appUserAccess->setMenuLabel("Round About");
        $appUserAccess->setMenuUrl("setting/roundAbout");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_SETTING ."|". AP::AL_ROUNDABOUT);
        $lists[] = $appUserAccess;

        $count = 0;
        foreach ($lists as $appUserAccess) {
            $appUserAccess->setStatusCode(active);
            $appUserAccess->setTreeSeq($seq + (10 * $count));
            $appUserAccess->save();
            $count++;
        }
    }

    public function constructApMemberOrder($seq)
    {
        $lists = array();

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::MOD_MEMBER_ORDER);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setMenuLabel("Member & Order");
        $appUserAccess->setMenuUrl("");
        $appUserAccess->setTreeLevel(1);
        $appUserAccess->setTreeStructure(AP::MOD_MEMBER_ORDER);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_MEMBER_LIST);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_MEMBER_ORDER);
        $appUserAccess->setMenuLabel("Member List");
        $appUserAccess->setMenuUrl("member/memberList");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_PRODUCT ."|". AP::AL_MEMBER_LIST);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_ORDER);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_MEMBER_ORDER);
        $appUserAccess->setMenuLabel("Order List");
        $appUserAccess->setMenuUrl("member/orderList");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_PRODUCT ."|". AP::AL_ORDER);
        $lists[] = $appUserAccess;

        $count = 0;
        foreach ($lists as $appUserAccess) {
            $appUserAccess->setStatusCode(active);
            $appUserAccess->setTreeSeq($seq + (10 * $count));
            $appUserAccess->save();
            $count++;
        }
    }

    public function constructApProduct($seq)
    {
        $lists = array();

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::MOD_PRODUCT);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setMenuLabel("Product");
        $appUserAccess->setMenuUrl("");
        $appUserAccess->setTreeLevel(1);
        $appUserAccess->setTreeStructure(AP::MOD_PRODUCT);
        $lists[] = $appUserAccess;

        $appUserAccess = new AppUserAccess();
        $appUserAccess->setAccessCode(AP::AL_PRODUCT);
        $appUserAccess->setIsAuthNeeded("Y");
        $appUserAccess->setIsMenu("Y");
        $appUserAccess->setParentId(AP::MOD_PRODUCT);
        $appUserAccess->setMenuLabel("Member List");
        $appUserAccess->setMenuUrl("member/memberList");
        $appUserAccess->setTreeLevel(2);
        $appUserAccess->setTreeStructure(AP::MOD_PRODUCT ."|". AP::AL_PRODUCT);
        $lists[] = $appUserAccess;

        $count = 0;
        foreach ($lists as $appUserAccess) {
            $appUserAccess->setStatusCode(active);
            $appUserAccess->setTreeSeq($seq + (10 * $count));
            $appUserAccess->save();
            $count++;
        }
    }
}
